package org.arl.modem.codec;

import java.io.File;
import java.io.FileInputStream;

public class RlEncodeDecode {

   public static void main(String[] args) {
      /*
       * Please remove comments below to use the relevant encoders
       * LinearRlEncoder -> Random linear fountain LtRlEncoder -> LT encoder
       * RsLtRlEncoder -> LT encoder with Kent map random number generator
       */

      String s = new String("/home/rohit/Desktop/test3.dat");
      File file = new File(s);
      byte[] b = new byte[(int) file.length()];
      try {
         FileInputStream fileInputStream = new FileInputStream(file);
         fileInputStream.read(b);
      } catch (Exception e) {
         e.printStackTrace();
      }

      System.out.println("Encoder parameters:2:66:100:5.0:" + b.length);

      // Encoder encode = new RLFountainEncoder(2, 66, 100, b);

      Encoder encode = new LTEncoder(2, 33, 100, (float) 0.01, (float) 5, b);

      // Encoder encode = new LTKentMapEncoder(2, 66, 100, (float) 5,
      // (float) 0.01, (float) 0.5, b);
      CodecPacket packet;

      // packet = new byte[encode.sizeOfPacket];
      long encodeStartTime = 0;
      long encodeStopTime = 0;
      encode.readMessage();
      long encodeTime = 0;

      /*
       * Please remove comments below to use the relevant decoder OfgRlDecoder
       * -> OFG decoder for both LT codes and random linear fountain
       * RsOfgRlDecoder -> OFG decoder for LT codes with Kent map random number
       * generator Encoder parameters:2:66:100:5.0:2000
       */

      // Decoder decode = new RLFountainDecoder(encode.numOfMessages,
      // encode.sizeOfPacket);

      Decoder decode = new LTDecoder(encode.numOfMessages, encode.sizeOfPacket);
      // Decoder decode = new LTKentMapDecoder(encode.numOfMessages,
      // encode.sizeOfPacket, (float) 0.7);
      System.out.println("Decode parameters:" + encode.numOfMessages + ":"
            + encode.sizeOfPacket);
      while (decode.DecodingSuccessful() != true) {
         // index++;
         encodeStartTime = encodeStopTime = encodeTime = 0;
         encodeStartTime = System.nanoTime();
         packet = encode.encodeMessage();
         encodeStopTime = System.nanoTime();
         encodeTime = (encodeStopTime - encodeStartTime);

         // encode.writePacket(packet);
         decode.decodeMessage(packet);
      }
      decode.writeMessage();

   }
}
